home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ultratk.exe / VIDEO.C < prev    next >
C/C++ Source or Header  |  1991-08-19  |  4KB  |  138 lines

  1.  
  2. /* video.c */
  3.  
  4. #include <conio.h>            /* MONO, BW80, etc are here */
  5. #include <dos.h>              /* MK_FP */
  6. #include "video.h"
  7.  
  8. video_status  CRT;            /* a global var */
  9.  
  10.  
  11. int  get_video_status ( void )
  12. {  
  13.    /* This function updates the global structure CRT */
  14.    
  15.    int  area;                 /* scratch var */
  16.    
  17.    CRT.mode      =         *(char far *) 0x449;
  18.    if ( CRT.mode==MONO ) CRT.location = 0xb000;                         
  19.    else if  ( CRT.mode > 3 )        return (1);/* no graphic modes allowed */
  20.    else              CRT.location = 0xb800;                      
  21.  
  22.    CRT.attr  = *(char far *) MK_FP ( CRT.location, 1 ); 
  23.    CRT.color = !((CRT.mode==BW40)||(CRT.mode==BW80)||(CRT.mode==MONO));
  24.    CRT.cols  = *( int far *) 0x44a;
  25.  
  26.    area      = *(int far *) 0x44c;
  27.    CRT.rows  = area / CRT.cols / 2;
  28.    CRT.rows  = (  CRT.rows >= 63 ) ? 63 :\
  29.                (  CRT.rows >= 60 ) ? 60 :\
  30.                (  CRT.rows >= 50 ) ? 50 :\
  31.                (  CRT.rows >= 44 ) ? 44 :\
  32.                (  CRT.rows >= 43 ) ? 43 :\
  33.                (  CRT.rows >= 36 ) ? 36 :\
  34.                (  CRT.rows >= 34 ) ? 34 : 25;
  35.  
  36.    return (0);
  37. }
  38.  
  39.  
  40. void put_char ( char c )
  41. {
  42.    /* This function is bios service 14:  it writes a char to the current
  43.       cursor position using the current attribute, then updates the cursor 
  44.       position.  It is faster than putchar() and better behaved than putch().
  45.    */
  46.  
  47.     _BH = 0;               /* page 0            */
  48.     _AL = c;               /* char to write     */
  49.     _AH = 14;              /* request func 14   */
  50.     geninterrupt (0x10);   /* video services    */
  51. }    
  52.     
  53.    
  54. int put_string ( char *string, int attribute, int row, int col )
  55. {
  56.    /* This function writes a string to a specific video location and also
  57.       lets the user specify an attribute.  However, it defaults to the 
  58.       current cursor position and attribute. E.G. put_string ("Hi",0,0,0);
  59.    */   
  60.       
  61.    char far *location;
  62.    int  offset, len=0;
  63.  
  64.    if (( col > CRT.cols )||( row > CRT.rows )) return (1);
  65.  
  66.    if ( attribute==0 ) attribute = CRT.attr;
  67.    if (( col==0 )||( row==0 )) { 
  68.       _BH = 0;                   /* page 0 */
  69.       _AH = 3;                   /* read cursor position */
  70.       geninterrupt (0x10);       /* video services */
  71.       col = _DL+1;
  72.       row = _DH+1;
  73.    }
  74.    
  75.    offset  = (row-1) * CRT.cols * 2  +  (col-1) * 2;    
  76.    location= (char far*) MK_FP ( CRT.location, offset ); 
  77.  
  78.    while ( *string ) {
  79.      *location++ = *string++;    /* put a char, increment both */
  80.      *location++ = attribute;    /* put attribute, increment location again */
  81.       len++;                     /* increment string length count */
  82.    }  
  83.    goto_rc ( row, col+len );     /* update the cursor position */
  84.    return (0);
  85.  
  86.  
  87. void   clear_screen     ( void )
  88. {
  89.    _BH = CRT.attr;       /* use the current attribute */
  90.    _CH = 0;              /* first row - all vars go from 0 to max-1  */
  91.    _CL = 0;              /* first col */
  92.    _DH = CRT.rows-1;     /* last row */
  93.    _DL = CRT.cols-1;     /* last col */
  94.    _AX = 0x0600;         /* scroll page up service */
  95.    geninterrupt (0x10);
  96.    
  97.    goto_rc ( 1,1 );      /* put cursor at 1,1 */
  98. }
  99.  
  100.  
  101. void  goto_rc ( int row, int col )
  102. {
  103.     /* This function positions the cursor to row, col.  It also wraps the
  104.        cursor around properly after a call to put_string().
  105.     */
  106.     
  107.     if ( col > CRT.cols ) {        
  108.        row    += col / CRT.cols;
  109.        col     = col % CRT.cols;
  110.     }   
  111.        
  112.    _BH = 0;               /* page 0 only */
  113.    _DH = row-1;           /* row and col params go from 0 to max-1 */
  114.    _DL = col-1;
  115.    _AH = 2;               
  116.    geninterrupt (0x10);   /* bios put cursor with AH = 2 */
  117. }
  118.  
  119.  
  120. void   hide_cursor     (void)
  121. {
  122.   _CX = 0x2000;                 /* High Fifth bit set = no cursor */
  123.   _AX = 0x0100;                 /* High Byte =1 = set cursor size */
  124.   geninterrupt(0x10);           
  125. }
  126.  
  127. void   show_cursor     (void)
  128. {
  129.   _CX = 0x000d;                 /* Std Cursor */
  130.   _AX = 0x0100;                 /* High Byte =1 = set cursor size */
  131.   geninterrupt(0x10);           
  132. }
  133.  
  134.  
  135. /* end video.c */
  136.  
  137.